package futbol5;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.List;
import javax.swing.AbstractAction;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.event.MouseInputListener;

/**
 *
 * @author Ivan
 */
public class PanelCanchas extends JPanel implements PropertyChangeListener, MouseInputListener {

    JScrollPane scroll = new javax.swing.JScrollPane();
    JScrollPane scrollEtiqueta = new javax.swing.JScrollPane();
    TablaFutbol5 tabla;
    JLabel etiqueta = new JLabel();
    Futbol5TableModel dm;

    public PanelCanchas(String nombre, List listaReservas) {

        setFont(new java.awt.Font("Trebuchet MS", 1, 14)); // NOI18N
        scroll.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);

        tabla = new TablaFutbol5(listaReservas);

        scroll.setViewportView(tabla);

        tabla.addMouseListener(this);

        etiqueta.setText(nombre);
        etiqueta.setHorizontalAlignment(JLabel.CENTER);
        scrollEtiqueta.setViewportView(etiqueta);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addComponent(scrollEtiqueta, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 720, Short.MAX_VALUE).addComponent(scroll, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 720, Short.MAX_VALUE)).addContainerGap()));
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(scrollEtiqueta, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(scroll, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE).addContainerGap()));

    }

    public void propertyChange(PropertyChangeEvent evt) {

        dm.fireTableDataChanged();

        System.out.println(evt.getPropertyName());

    }

    public void mouseClicked(MouseEvent e) {
    }

    public void mousePressed(MouseEvent e) {
    }

    public void mouseReleased(MouseEvent e) {
        System.out.println(e.getComponent().getClass().toString());
        if (e.getButton() == MouseEvent.BUTTON1) {
            System.out.println(e.toString());

            JPopupMenu menu = new JPopupMenu();
            JMenuItem item = new JMenuItem(new AbstractAction("Iniciar Partido") {

                public void actionPerformed(ActionEvent e) {
                    tabla.cambiarModo("BARRA");
                }
            });
            menu.add(item);
            //SEGUNDA OPCION PARA PROBAR...
            item = new JMenuItem(new AbstractAction("Terminar Partido") {

                public void actionPerformed(ActionEvent e) {
                    tabla.cambiarModo("VACIA");
                }
            });
            menu.add(item);

            menu.show(e.getComponent(), e.getX(), e.getY());

        }
    }

    public void mouseEntered(MouseEvent e) {
    }

    public void mouseExited(MouseEvent e) {
    }

    public void mouseDragged(MouseEvent e) {
    }

    public void mouseMoved(MouseEvent e) {
    }
}
